# Makefile for Go application with Docker Compose

# Project variables
PROJECT_NAME := go-clean-template
APP_CONTAINER := app

.PHONY: build up down clean logs migrate

# Build the application Docker image
build:
	@echo "Building Docker image..."
	docker compose build $(APP_CONTAINER)

# Start all services in detached mode
up: build
	@echo "Starting services..."
	docker compose up -d

# Stop and remove all containers
down:
	@echo "Stopping services..."
	docker compose down

# Clean project (containers, volumes, networks)
clean: down
	@echo "Removing all project resources..."
	docker compose down --volumes --rmi local
	@echo "Cleaning Docker system..."
	docker system prune -f

# View container logs (follow mode)
logs:
	docker compose logs -f $(APP_CONTAINER)

# Run database migrations
migrate:
	@echo "Running database migrations..."
	docker compose run --rm $(APP_CONTAINER) /app migrate

# SSH into app container
ssh-app:
	docker compose exec $(APP_CONTAINER) /bin/sh